package com.stone.juc;

/**
 * 题目： 三个售票员 ， 买出 30 张票
 * 如何编写企业级的多线程代码？
 */
public class SaleTicketDemo01 {

    public static void main(String[] args) {

        for (int i = 0; i < 100; i++) {
            Ticket ticket = new Ticket();
            new Thread(() -> {
                ticket.sale("张三");
            }).start();

            new Thread(() -> {
                ticket.sale("李四");
            }).start();

            new Thread(() -> {
                ticket.sale("王五");
            }).start();
        }
    }
}

class Ticket {
    private int number = 10;

    public void sale(String name) {
        while (number > 0) {
            System.err.println(name + " 售票员售卖 " + number-- + " 张票。");
        }
    }
}